<?php

namespace patterns;
/**
 * Singleton
 *
 */
class Singleton
{
	/**
	 * Holds the object of a singletone class
	 *
	 * @var unknown_type
	 */
	private static $instance = null;

	/**
	 * No direct init
	 *
	 */
	protected function __construct()
	{
	}

	/**
	 * No cloning
	 *
	 */
	final private function __clone()
	{
	}

	/**
	 * Returns singleton instance
	 *
	 * @return unknown
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			if (defined("_CORE_CREATED"))
			{
				die("Second core creation! Please redesign your code!");
			}

			//God bless PHP 5.3
			$className = "\\".get_called_class();

			define("_CORE_CREATED", true);

			self::$instance = new $className;
		}

		return self::$instance;
	}
}